Skip to main content

selenium 启动Chrome浏览器报错

报错代码

driver = webdriver.Chrome() 

错误信息

Traceback (most recent call last):
File "E:\PythonProjects\Demo1\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\xiaokang\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:\Users\xiaokang\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "E:/PythonProjects/Demo1/main.py", line 6, in <module>
driver = webdriver.Chrome() # Chrome浏览器
File "E:\PythonProjects\Demo1\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "E:\PythonProjects\Demo1\venv\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

浏览器输入 chrome://version/

找到版本信息 如

Google Chrome 83.0.4103.97 (正式版本) (64 位)

下载 chrome驱动

http://chromedriver.storage.googleapis.com/index.html

找到对应的版本下载下来,下载的是个解压包,解压出来会有一个chromedriver.exe文件

要把这个chromedriver.exe文件拷贝到2个目录里,一个是chrome浏览器的根目录,一个是pyhton的安装目录

然后再运行程序就没有错误了

参考 https://blog.csdn.net/weixin_44318830/article/details/103339273